/*
 * @Author: xujianxing
 * @Date: 2020-03-15 10:58:15
 * @LastEditors  : xujianxing
 * @LastEditTime : 2020-03-15 12:31:07
 * @Description: file content
 */
import { RECEIVE_CURRENT_SONG, SET_FULL_SCREEN } from "./types";
import { getSongComment, getLyric, getSongUrl } from "../../../api/summary";

const receiveCurrentSong = data => ({
  type: RECEIVE_CURRENT_SONG,
  data
});

/** 切换全屏状态 */
export const toggleFullScreen = data => ({ type: SET_FULL_SCREEN, data });

export const perfectSong = song => async (dispatch, getState) => {
  const { id } = song;
  const { currentSong } = getState().player;
  if (currentSong.id === id) return;
  try {
    const lrcRes = await getLyric(id);
    const cmtRes = await getSongComment(id);
    const urlRes = await getSongUrl(id);
    if (lrcRes.code === 200 && cmtRes.code === 200 && urlRes.code === 200) {
      song.lrc = lrcRes.lrc;
      song.comments = cmtRes.comments;
      song.url = urlRes.data[0].url;
      dispatch(receiveCurrentSong(song));
    }
  } catch (error) {}
};
